<template>
	<section class="ToLogin">
		<div class=" plr30">
			<p class="title centre mud50">汽车分销系统</p>
			<ul class="logUl">
				<li class="log_li bbtm hei100 flexs">
					<input class="flex1 sz30" type="text" name="" placeholder="手机号" v-model="myphone">
				</li>
				<li class="log_li bbtm hei100 flexs">
					<input class="flex1 sz30" type="password" name="" placeholder="输入登录密码" v-model="mypawds">
				</li>
			</ul>
			<button class="btns " :class="{walld44:isShow}" @click="OnceLogin()">登录</button>
			<span>{{filterPhone}}</span>

		</div>
	</section>
</template>
<script type="text/javascript">
	import { Toast } from 'mint-ui';
	import { Indicator } from 'mint-ui';
	import Qs from 'qs';
	import md5 from 'js-md5';
	export default {
		name: 'ToLogin',
		data() {
			return {
				myphone: '',
				mypawds: '',
				isShow: false
			}
		},
		created: function() {

		},
		computed: {
			filterPhone: function() {
				if(this.myphone.length > 10) {
					this.isShow = true
				} else {
					this.isShow = false
				}
			}
		},
		mounted: function() {
			this.Estimate();
		},
		methods: {
			//点击登录
			OnceLogin: function() {
				if(this.isShow == true) {
					if(/^1\d{10}$/.test(this.myphone)) {
						Indicator.open({
							spinnerType: 'snake'
						});
						this.$http.post("/WorkMembers/v1.0/AccountLogin", Qs.stringify({
							"Account": this.myphone,
							"Pwd": md5(this.mypawds)
						})).then((res) => {
							console.log(res.data);
							if(res.data.Return_Data == "") {
								Toast(res.data.Return_Mess)
								Indicator.close();
								this.$router.push({
									path: '/loginAll'
								})
							} else {
								sessionStorage.MembersID = res.data.Return_Data;
								Indicator.close();
								this.$router.replace({
									path: '/ownAll'
								});
							}

						}).catch((err) => {
							console.log(err);
						});

					} else {
						Toast("请输入正确手机号~")
					}
				} else {
					Toast("不能为空哟~")
				}
			},
			//sessionStorage
			Estimate: function() {
				if(!sessionStorage.getItem("MembersID") || sessionStorage.getItem("MembersID") == 'undefined') {
					console.log(this.MembersID);
					this.$router.push({
						path: '/loginAll'
					}) //进来判断是否已经有账号
				} else {
					//如果有进入下一个页面
					//					this.$router.push({
					//						path: '/cardoilAll'
					//					})
				}
			}
		}
	}
</script>
<style scoped>

</style>